package com.xindacloud.sms.adapter.utils;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

public class DateHelp {

    private static DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    public static String Y_M_D_H_M_S_PATTERN = "yyyy-MM-dd HH:mm:ss";
    public static String Y_M_D_T_H_M_S_PATTERN = "yyyy-MM-dd'T'HH:mm:ss";

    public static LocalDateTime str2LocalDateTimePlusHours(String dateTime, String dateFormatter, Integer hours) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormatter);
        LocalDateTime localDateTime = LocalDateTime.parse(dateTime, formatter);
        return localDateTime.plusHours(hours);
    }

    public static LocalDateTime nowDateTimeMinusHours(int hours) {
        LocalDateTime localDateTime = LocalDateTime.now();
        localDateTime.atZone(ZoneId.of("Asia/Shanghai"));
        return localDateTime.minusHours(hours);
    }

    public static String localDateTime2Str(LocalDateTime localDateTime) {
        return localDateTime.format(FORMATTER);
    }
}
